import datetime
import functools
import logging

from absl import app

import experimental.prophet as prophet
from experimental.prophet.craps.interval import feature


def gen_matrix(name, feature_func, interval):
  ts = prophet.global_timestamp()
  timer = prophet.timer(interval)

  with prophet.namespace(name):
    row = feature_func(interval)

  with prophet.control_if(ts % prophet.to_duration_int(interval) == 0):
    aggregator = prophet.scalar_value_aggregator([ts, *row])
  return aggregator


def main(argv):
  mats = {}
  for name, feature_func in feature.FEATURE_INSTANCES.items():
    mat = prophet.run_from_fastfeed_multiprocess(functools.partial(gen_matrix,
                                                                   name,
                                                                   feature_func,
                                                                   '10s'),
                                                 datetime.date(2019, 8, 1),
                                                 datetime.datetime(2019, 8, 1, 2),
                                                 machine='feed-01.ap-northeast-1.aws')
    mats[name] = mat

    print(name)
    print(mat)
    print('---')


if __name__ == '__main__':
  logging.basicConfig(level='DEBUG')
  app.run(main)
